package com.departmentstore.dto;

import com.departmentstore.entity.Manufacturer;
import com.departmentstore.entity.ManufacturerProduct;
import com.departmentstore.entity.Product;
import lombok.Data;
import java.math.BigDecimal;

@Data
public class ManufacturerProductDTO {
    private String manufacturerId;   // 制造商ID
    private String manufacturerName; // 制造商名称
    private String productId;        // 商品ID
    private String productName;      // 商品名称
    private String productModel;     // 商品型号
    private BigDecimal supplyPrice;  // 供货价格
    private String address;
    private String phone;
    private String email;
    private String contactPerson;

    // 无参构造函数（必须）
    public ManufacturerProductDTO() {}

    // 带参构造函数（从实体类转换）
    public ManufacturerProductDTO(ManufacturerProduct mp) {
        // 提取制造商信息（处理空值）
        Manufacturer manufacturer = mp.getManufacturer();
        this.manufacturerId = (manufacturer != null) ? manufacturer.getManufacturerId() : "未知制造商ID";
        this.manufacturerName = (manufacturer != null) ? manufacturer.getName() : "未知制造商";
        this.address = (manufacturer != null) ? manufacturer.getAddress() : "未知地址";
        this.contactPerson = (manufacturer != null) ? manufacturer.getContactPerson() : "未知联系人";
        this.email = (manufacturer != null) ? manufacturer.getEmail():"";
        this.phone = (manufacturer != null) ? manufacturer.getPhone():"";

        // 提取商品信息（处理空值）
        Product product = mp.getProduct();
        this.productId = (product != null) ? product.getProductId() : "未知商品ID";
        this.productName = (product != null) ? product.getName() : "未知商品";
        this.productModel = (product != null) ? product.getModel() : "未知型号";

        // 直接字段映射
        this.supplyPrice = mp.getPrice();
    }
}